home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Mac Game Programming Gurus / TricksOfTheMacGameProgrammingGurus.iso / CodeWarrior Lite / Metrowerks C⁄C++ Lite / Headers / Universal Headers 2.0.1f / Threads.h < prev    next >
Encoding:
C/C++ Source or Header  |  1995-03-22  |  6.3 KB  |  182 lines  |  [TEXT/MMCC]

  1. /*
  2.      File:        Threads.h
  3.  
  4.      Contains:    Thread Manager Interfaces.
  5.  
  6.      Version:    Technology:    System 7.5
  7.                  Package:    Universal Interfaces 2.0 in “MPW Latest” on ETO #17
  8.  
  9.      Copyright:    © 1984-1995 by Apple Computer, Inc.
  10.                  All rights reserved.
  11.  
  12.      Bugs?:        If you find a problem with this file, use the Apple Bug Reporter
  13.                  stack.  Include the file and version information (from above)
  14.                  in the problem description and send to:
  15.                      Internet:    apple.bugs@applelink.apple.com
  16.                      AppleLink:    APPLE.BUGS
  17.  
  18. */
  19.  
  20. #ifndef __THREADS__
  21. #define __THREADS__
  22.  
  23.  
  24. #ifndef __ERRORS__
  25. #include <Errors.h>
  26. #endif
  27. /*    #include <ConditionalMacros.h>                                */
  28.  
  29. #ifndef __MEMORY__
  30. #include <Memory.h>
  31. #endif
  32. /*    #include <Types.h>                                            */
  33. /*    #include <MixedMode.h>                                        */
  34.  
  35. #ifdef __cplusplus
  36. extern "C" {
  37. #endif
  38.  
  39. #if PRAGMA_ALIGN_SUPPORTED
  40. #pragma options align=mac68k
  41. #endif
  42.  
  43. #if PRAGMA_IMPORT_SUPPORTED
  44. #pragma import on
  45. #endif
  46.  
  47. typedef unsigned short ThreadState;
  48.  
  49.  
  50. enum {
  51.     kReadyThreadState            = 0,
  52.     kStoppedThreadState            = 1,
  53.     kRunningThreadState            = 2
  54. };
  55.  
  56. /* Error codes have been meoved to Errors.(pah) */
  57. /* Thread environment characteristics */
  58. typedef void *ThreadTaskRef;
  59.  
  60. /* Thread characteristics */
  61. typedef unsigned long ThreadStyle;
  62.  
  63.  
  64. enum {
  65.     kCooperativeThread            = 1L << 0,
  66.     kPreemptiveThread            = 1L << 1
  67. };
  68.  
  69. /* Thread identifiers */
  70. typedef unsigned long ThreadID;
  71.  
  72.  
  73. enum {
  74.     kNoThreadID                    = 0,
  75.     kCurrentThreadID            = 1,
  76.     kApplicationThreadID        = 2
  77. };
  78.  
  79. /* Options when creating a thread */
  80. typedef unsigned long ThreadOptions;
  81.  
  82.  
  83. enum {
  84.     kNewSuspend                    = (1 << 0),
  85.     kUsePremadeThread            = (1 << 1),
  86.     kCreateIfNeeded                = (1 << 2),
  87.     kFPUNotNeeded                = (1 << 3),
  88.     kExactMatchThread            = (1 << 4)
  89. };
  90.  
  91. /* Information supplied to the custom scheduler */
  92. struct SchedulerInfoRec {
  93.     unsigned long                    InfoRecSize;
  94.     ThreadID                        CurrentThreadID;
  95.     ThreadID                        SuggestedThreadID;
  96.     ThreadID                        InterruptedCoopThreadID;
  97. };
  98. typedef struct SchedulerInfoRec SchedulerInfoRec;
  99.  
  100. typedef SchedulerInfoRec *SchedulerInfoRecPtr;
  101.  
  102. /*
  103.     The following ProcPtrs cannot be interchanged with UniversalProcPtrs because
  104.     of differences between 680x0 and PowerPC runtime architectures with regard to
  105.     the implementation of the Thread Manager.
  106.  */
  107. /* Prototype for thread's entry (main) routine */
  108. typedef void *voidPtr;
  109.  
  110. typedef pascal voidPtr (*ThreadEntryProcPtr)(void *threadParam);
  111. /* Prototype for custom thread scheduler routine */
  112. typedef pascal ThreadID (*ThreadSchedulerProcPtr)(SchedulerInfoRecPtr schedulerInfo);
  113. /* Prototype for custom thread switcher routine */
  114. typedef pascal void (*ThreadSwitchProcPtr)(ThreadID threadBeingSwitched, void *switchProcParam);
  115. /* Prototype for thread termination notification routine */
  116. typedef pascal void (*ThreadTerminationProcPtr)(ThreadID threadTerminated, void *terminationProcParam);
  117. /* Prototype for debugger NewThread notification */
  118. typedef pascal void (*DebuggerNewThreadProcPtr)(ThreadID threadCreated);
  119. /* Prototype for debugger DisposeThread notification */
  120. typedef pascal void (*DebuggerDisposeThreadProcPtr)(ThreadID threadDeleted);
  121. /* Prototype for debugger schedule notification */
  122. typedef pascal ThreadID (*DebuggerThreadSchedulerProcPtr)(SchedulerInfoRecPtr schedulerInfo);
  123. /* Thread Manager routines */
  124. extern pascal OSErr CreateThreadPool(ThreadStyle threadStyle, short numToCreate, Size stackSize)
  125.  THREEWORDINLINE(0x303C, 0x0501, 0xABF2);
  126. extern pascal OSErr GetFreeThreadCount(ThreadStyle threadStyle, short *freeCount)
  127.  THREEWORDINLINE(0x303C, 0x0402, 0xABF2);
  128. extern pascal OSErr GetSpecificFreeThreadCount(ThreadStyle threadStyle, Size stackSize, short *freeCount)
  129.  THREEWORDINLINE(0x303C, 0x0615, 0xABF2);
  130. extern pascal OSErr GetDefaultThreadStackSize(ThreadStyle threadStyle, Size *stackSize)
  131.  THREEWORDINLINE(0x303C, 0x0413, 0xABF2);
  132. extern pascal OSErr ThreadCurrentStackSpace(ThreadID thread, unsigned long *freeStack)
  133.  THREEWORDINLINE(0x303C, 0x0414, 0xABF2);
  134. extern pascal OSErr NewThread(ThreadStyle threadStyle, ThreadEntryProcPtr threadEntry, void *threadParam, Size stackSize, ThreadOptions options, void **threadResult, ThreadID *threadMade)
  135.  THREEWORDINLINE(0x303C, 0x0E03, 0xABF2);
  136. extern pascal OSErr DisposeThread(ThreadID threadToDump, void *threadResult, Boolean recycleThread)
  137.  THREEWORDINLINE(0x303C, 0x0504, 0xABF2);
  138. extern pascal OSErr YieldToThread(ThreadID suggestedThread)
  139.  THREEWORDINLINE(0x303C, 0x0205, 0xABF2);
  140. extern pascal OSErr YieldToAnyThread(void)
  141.  FOURWORDINLINE(0x42A7, 0x303C, 0x0205, 0xABF2);
  142. extern pascal OSErr GetCurrentThread(ThreadID *currentThreadID)
  143.  THREEWORDINLINE(0x303C, 0x0206, 0xABF2);
  144. extern pascal OSErr GetThreadState(ThreadID threadToGet, ThreadState *threadState)
  145.  THREEWORDINLINE(0x303C, 0x0407, 0xABF2);
  146. extern pascal OSErr SetThreadState(ThreadID threadToSet, ThreadState newState, ThreadID suggestedThread)
  147.  THREEWORDINLINE(0x303C, 0x0508, 0xABF2);
  148. extern pascal OSErr SetThreadStateEndCritical(ThreadID threadToSet, ThreadState newState, ThreadID suggestedThread)
  149.  THREEWORDINLINE(0x303C, 0x0512, 0xABF2);
  150. extern pascal OSErr SetThreadScheduler(ThreadSchedulerProcPtr threadScheduler)
  151.  THREEWORDINLINE(0x303C, 0x0209, 0xABF2);
  152. extern pascal OSErr SetThreadSwitcher(ThreadID thread, ThreadSwitchProcPtr threadSwitcher, void *switchProcParam, Boolean inOrOut)
  153.  THREEWORDINLINE(0x303C, 0x070A, 0xABF2);
  154. extern pascal OSErr SetThreadTerminator(ThreadID thread, ThreadTerminationProcPtr threadTerminator, void *terminationProcParam)
  155.  THREEWORDINLINE(0x303C, 0x0611, 0xABF2);
  156. extern pascal OSErr ThreadBeginCritical(void)
  157.  THREEWORDINLINE(0x303C, 0x000B, 0xABF2);
  158. extern pascal OSErr ThreadEndCritical(void)
  159.  THREEWORDINLINE(0x303C, 0x000C, 0xABF2);
  160. extern pascal OSErr SetDebuggerNotificationProcs(DebuggerNewThreadProcPtr notifyNewThread, DebuggerDisposeThreadProcPtr notifyDisposeThread, DebuggerThreadSchedulerProcPtr notifyThreadScheduler)
  161.  THREEWORDINLINE(0x303C, 0x060D, 0xABF2);
  162. extern pascal OSErr GetThreadCurrentTaskRef(ThreadTaskRef *threadTRef)
  163.  THREEWORDINLINE(0x303C, 0x020E, 0xABF2);
  164. extern pascal OSErr GetThreadStateGivenTaskRef(ThreadTaskRef threadTRef, ThreadID threadToGet, ThreadState *threadState)
  165.  THREEWORDINLINE(0x303C, 0x060F, 0xABF2);
  166. extern pascal OSErr SetThreadReadyGivenTaskRef(ThreadTaskRef threadTRef, ThreadID threadToSet)
  167.  THREEWORDINLINE(0x303C, 0x0410, 0xABF2);
  168.  
  169. #if PRAGMA_IMPORT_SUPPORTED
  170. #pragma import off
  171. #endif
  172.  
  173. #if PRAGMA_ALIGN_SUPPORTED
  174. #pragma options align=reset
  175. #endif
  176.  
  177. #ifdef __cplusplus
  178. }
  179. #endif
  180.  
  181. #endif /* __THREADS__ */
  182.